//package deque;
/*
 * Description:用数组实现双端队列
 * Author: AMark
 * Date:1/23/2024
 * Time:3:34 PM
 */

import java.util.Vector;

public class ArrayDeque<T> {
    //初始大小为8
    private int size = 8;
    //数组
    private Vector<T> items;
    //构造函数构造一个初始大小为8的数组
    public ArrayDeque() {
        items = new Vector<T>(size);
    }
    //头插法
    public void addFirst(T x) {
        items.add(0, x);
    }
    //尾插法
    public void addLast(T x) {
        items.add(x);
    }
    //判断是否为空
    public boolean isEmpty() {
        return items.isEmpty();
    }
    //获得大小
    public int size() {
        return items.size();
    }
    //打印
    public void printDeque() {
        for (T item : items) {
            System.out.print(item + " ");
        }
        System.out.println();
    }
    //删除头元素
    public T removeFirst() {
        return items.remove(0);
    }
    //删除尾元素
    public T removeLast() {
        return items.remove(items.size() - 1);
    }
    //获得index处的元素
    public T get(int index) {
        return items.get(index);
    }
}
